package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.GysInfoExample.E_ADDRESS;
import static org.jsola.hr.example.GysInfoExample.E_BUSINESS_LICENSE_URL;
import static org.jsola.hr.example.GysInfoExample.E_CONTACT_EMAIL;
import static org.jsola.hr.example.GysInfoExample.E_CONTACT_NAME;
import static org.jsola.hr.example.GysInfoExample.E_CONTACT_PHONE;
import static org.jsola.hr.example.GysInfoExample.E_CONTACT_SEX;
import static org.jsola.hr.example.GysInfoExample.E_CONTACT_WX;
import static org.jsola.hr.example.GysInfoExample.E_CONTENT;
import static org.jsola.hr.example.GysInfoExample.E_CONTRACT_LIFE;
import static org.jsola.hr.example.GysInfoExample.E_CONTRACT_URL;
import static org.jsola.hr.example.GysInfoExample.E_CORPORATE_EMAIL;
import static org.jsola.hr.example.GysInfoExample.E_CORPORATE_NAME;
import static org.jsola.hr.example.GysInfoExample.E_CORPORATE_PHONE;
import static org.jsola.hr.example.GysInfoExample.E_CORPORATE_SEX;
import static org.jsola.hr.example.GysInfoExample.E_CORPORATE_WX;
import static org.jsola.hr.example.GysInfoExample.E_GROUP_ID;
import static org.jsola.hr.example.GysInfoExample.E_GYS_NAME;
import static org.jsola.hr.example.GysInfoExample.E_OTHER_FILE_URL;
import static org.jsola.hr.example.GysInfoExample.E_REMARK;
import static org.jsola.hr.example.GysInfoExample.N_ADDRESS;
import static org.jsola.hr.example.GysInfoExample.N_BUSINESS_LICENSE_URL;
import static org.jsola.hr.example.GysInfoExample.N_CONTACT_EMAIL;
import static org.jsola.hr.example.GysInfoExample.N_CONTACT_NAME;
import static org.jsola.hr.example.GysInfoExample.N_CONTACT_PHONE;
import static org.jsola.hr.example.GysInfoExample.N_CONTACT_SEX;
import static org.jsola.hr.example.GysInfoExample.N_CONTACT_WX;
import static org.jsola.hr.example.GysInfoExample.N_CONTENT;
import static org.jsola.hr.example.GysInfoExample.N_CONTRACT_LIFE;
import static org.jsola.hr.example.GysInfoExample.N_CONTRACT_URL;
import static org.jsola.hr.example.GysInfoExample.N_CORPORATE_EMAIL;
import static org.jsola.hr.example.GysInfoExample.N_CORPORATE_NAME;
import static org.jsola.hr.example.GysInfoExample.N_CORPORATE_PHONE;
import static org.jsola.hr.example.GysInfoExample.N_CORPORATE_SEX;
import static org.jsola.hr.example.GysInfoExample.N_CORPORATE_WX;
import static org.jsola.hr.example.GysInfoExample.N_GROUP_ID;
import static org.jsola.hr.example.GysInfoExample.N_GYS_NAME;
import static org.jsola.hr.example.GysInfoExample.N_OTHER_FILE_URL;
import static org.jsola.hr.example.GysInfoExample.N_REMARK;

/**
 * 供应商信息表
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class GysInfoQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_GROUP_ID, example = E_GROUP_ID)
    @Length(max = 50)
    private String groupId;

    @ApiParam(value = N_GYS_NAME, example = E_GYS_NAME)
    @Length(max = 255)
    private String gysName;

    @ApiParam(value = N_CONTENT, example = E_CONTENT)
    private String content;

    @ApiParam(value = N_CONTRACT_LIFE, example = E_CONTRACT_LIFE)
    @Length(max = 255)
    private String contractLife;

    @ApiParam(value = N_ADDRESS, example = E_ADDRESS)
    @Length(max = 255)
    private String address;

    @ApiParam(value = N_REMARK, example = E_REMARK)
    @Length(max = 255)
    private String remark;

    @ApiParam(value = N_CONTRACT_URL, example = E_CONTRACT_URL)
    private String contractUrl;

    @ApiParam(value = N_BUSINESS_LICENSE_URL, example = E_BUSINESS_LICENSE_URL)
    private String businessLicenseUrl;

    @ApiParam(value = N_OTHER_FILE_URL, example = E_OTHER_FILE_URL)
    private String otherFileUrl;

    @ApiParam(value = N_CONTACT_NAME, example = E_CONTACT_NAME)
    @Length(max = 255)
    private String contactName;

    @ApiParam(value = N_CONTACT_SEX, example = E_CONTACT_SEX)
    @Length(max = 255)
    private String contactSex;

    @ApiParam(value = N_CONTACT_PHONE, example = E_CONTACT_PHONE)
    @Length(max = 255)
    private String contactPhone;

    @ApiParam(value = N_CONTACT_EMAIL, example = E_CONTACT_EMAIL)
    @Length(max = 255)
    private String contactEmail;

    @ApiParam(value = N_CONTACT_WX, example = E_CONTACT_WX)
    @Length(max = 255)
    private String contactWX;

    @ApiParam(value = N_CORPORATE_NAME, example = E_CORPORATE_NAME)
    @Length(max = 255)
    private String corporateName;

    @ApiParam(value = N_CORPORATE_SEX, example = E_CORPORATE_SEX)
    @Length(max = 255)
    private String corporateSex;

    @ApiParam(value = N_CORPORATE_PHONE, example = E_CORPORATE_PHONE)
    @Length(max = 255)
    private String corporatePhone;

    @ApiParam(value = N_CORPORATE_EMAIL, example = E_CORPORATE_EMAIL)
    @Length(max = 255)
    private String corporateEmail;

    @ApiParam(value = N_CORPORATE_WX, example = E_CORPORATE_WX)
    @Length(max = 255)
    private String corporateWX;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public GysInfoQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

    private String searchKey;

    private String siteId;

}

